//
// Created by 赵李言 on 2022/4/11.
//

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int n,m;
int main(){
    cin>>n>>m;
    int a[20];
    memset(a, 0, 20*4);
    for (int i = 20-1; i >=0; --i) {
        int x=1;
        for (int j = 0; j < i; ++j) {
            x*=m;
        }
        if(n>=x){
            a[i]=n/x;
            n=n%x;
        }
    }
    bool f0= true;
    for (int i = 19; i >= 0; --i) {
        if(a[i]==0){
            if(f0){
                continue;
            }
        }
        else
            f0= false;
        if(a[i]<10){
            cout<<a[i];
        }
        else{
            cout<<(char)('A'-10+a[i]);
        }
    }
}